package com.mingqijia.gassafety.gateway.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author mby
 * @version v1.0.1
 * @date 2024年03月12日 10:07
 */
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class MySwaggerConfig {

    /** 是否开启swagger */
    @Value("${swagger.enabled:false}")
    private boolean enabled;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .enable(enabled)
            .select()
            // 扫描指定包路径下的swagger注解
            .apis(RequestHandlerSelectors.basePackage("com.mingqijia.gassafety.console.controller"))
            .paths(PathSelectors.any())
            .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("API文档")
            .description("详细描述")
            .termsOfServiceUrl("http://localhost:9931")
            .contact(new Contact("作者", "http://localhost:9931", "email@example.com"))
            .version("1.0")
            .build();
    }
}